package com.hst.web.base.proxy;

import java.util.*;

import org.springframework.beans.factory.annotation.Autowired;

import com.hst.core.Page;
import com.hst.core.ServiceContext;
import com.hst.core.dao.IORDao;
import com.hst.core.dao.ISQLDao;
import com.hst.core.meta.MetaData;
import com.hst.core.meta.MetaRepository;
import com.hst.core.meta.proxies.DefaultDataProxy;
import com.hst.web.auth.po.User;
import com.hst.web.base.ui.OldCardVehicle;

public class OldCardVehicleProxy extends DefaultDataProxy {

    @Autowired
    ISQLDao sql;

    @Autowired
    MetaRepository mr;

    @SuppressWarnings("unchecked")
    @Override
    public Page<?> list(Map<String, ?> query, int pageIdx) {
        return sql.list("oldcard.list-oldcard-vehicle", query, pageIdx, Page.getPageSize());
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<?> list(Map<String, ?> query) {
        return sql.query("oldcard.list-oldcard-vehicle", query);
    }

    @Override
    public Object save(MetaData data) throws Exception {
    	User u = (User) ServiceContext.getInstance().getUser();
        Map<String, String> map = new HashMap<>();
        OldCardVehicle e = (OldCardVehicle) data;
        map.put("rowID", e.getRowID());
        map.put("fullname", e.getFullname());
        map.put("ownerName", e.getOwnerName());
        map.put("plateNo", e.getPlateNo());
        map.put("passAcsNo", e.getPassAcsNo());
        map.put("passOld", e.getPassOld());
        map.put("oldpassStatus", e.getOldpassStatus());
        
        if (e.getOp() == MetaData.OP_NEW) {
        	sql.create("oldcard.insert-oldcard-vehicle", map);
        } else {
        	sql.update("oldcard.update-oldcard-vehicle", map);
        }
        return e;
    }

    @Override
    public Object del(MetaData data) throws Exception {
    	OldCardVehicle e = (OldCardVehicle) data;
        Map<String, String> map = new HashMap<>();
        map.put("rowID", e.getRowID());
        sql.delete("oldcard.delete-oldcard-vehicle", map);
        return data;
    }

}
